<template>
  <!-- 汇付提现记录 -->
  <el-dialog title="提现记录" :visible.sync="dialogVisible" :close-on-click-modal="false" width="1200px" append-to-body>
    <el-form class="search-form-new" :model="queryParams" ref="queryForm" :inline="true">
      <div class="search-box">

        <el-form-item label="日期" prop="acctDate">
          <el-date-picker v-model="timer" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" placeholder="请选择日期" value-format="yyyyMMdd" :clearable="false">
          </el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="类型" prop="status">
          <el-select clearable v-model="queryParams.status" placeholder="请选择类型"  >
            <el-option  label="充值" :value="1" />
            <el-option  label="扣除" :value="2" />
          </el-select>
        </el-form-item> -->

        <el-form-item class="btns">
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <!-- <el-button icon="el-icon-refresh" @click="resetQuery">重置/刷新</el-button> -->
        </el-form-item>
      </div>
    </el-form>
    <div class="table_box">
      <el-table :data="tableData.records" style="width: 100%" stripe border>
      
        <el-table-column prop="trans_date" label="提现日期" width="165">
          <template slot-scope="scope">
            <span>{{ formatTime(scope.row.trans_date) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="card_name" label="账户名称"></el-table-column>
        <el-table-column prop="card_no" label="账户号"></el-table-column>
        <el-table-column prop="trans_amt" label="提现金额"></el-table-column>
        <el-table-column prop="trans_stat" label="状态">
          <template slot-scope="scope">
            <span v-if="scope.row.trans_stat=='I'||scope.row.trans_stat=='P'" style="color: yellowgreen;">处理中</span>
            <span v-if="scope.row.trans_stat=='S'" style="color: #00c03c;">成功</span>
            <span v-if="scope.row.trans_stat=='F'" style="color: red;">失败</span>
          </template>
        </el-table-column>

      </el-table>

      <pagination :layout="'prev,next'" :total="tableData.total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    </div>
  </el-dialog>

</template>
<script>
import { mapGetters } from "vuex";
import { settlementQueryMx } from "@/api/tenantApis/tenantManage";
export default {
  name: "",
  computed: {
    ...mapGetters(["userInfo"]),
  },
  data() {
    return {
      dialogVisible: false,
      timer: [],
      tableData: {
        records: [],
        total: 0,
      },

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        beginDate: "",
        endDate: "",
      },
    };
  },
  created() {},
  computed: {
    formatTime() {
      return (time) => {
        const year = time.slice(0, 4);
        const month = time.slice(4, 6);
        const day = time.slice(6, 8);
        return `${year}-${month}-${day}`;
      };
    },
  },
  methods: {
    open() {
      const now = new Date();
      const year = now.getFullYear();
      const month = now.getMonth() + 1;
      const day = now.getDate();
      this.queryParams.endDate = `${year}${month > 9 ? month : "0" + month}${
        day > 9 ? day : "0" + day
      }`;

      // 获取当前日期
      let currentDate = new Date();
      // 获取七天前的日期
      currentDate.setDate(currentDate.getDate() - 7);
      const year2 = currentDate.getFullYear();
      const month2 = currentDate.getMonth() + 1;
      const day2 = currentDate.getDate();
      this.queryParams.beginDate = `${year2}${month2 > 9 ? month2 : "0" + month2}${
        day2 > 9 ? day2 : "0" + day2
      }`;

      
      this.timer = [this.queryParams.beginDate,this.queryParams.endDate]
      this.dialogVisible = true;
      this.getList();
    },
    // 获取列表
    getList() {
      // queryParams 请求列表
      this.loading = true;
      if (this.timer && this.timer.length == 2) {
        this.queryParams.beginDate = this.timer[0] ;
        this.queryParams.endDate = this.timer[1] ;
      } else {
        this.queryParams.beginDate = "";
        this.queryParams.endDate = "";
      }

      // const obj = {
      //   pageSize:10,
      //   pageNum:1,
      //   beginDate:20250311,
      //   endDate:20250311,
      // }
      // settlementQueryMx(obj).then(res=>{
      //   if(res.data&&res.data.data&&res.data.data.trans_log_result_list){
      //     const obj = JSON.parse(res.data.data.trans_log_result_list)
      //     console.log("%c Line:890 🥒 obj", "color:#fca650", obj);
        
      //   }
      // })

      settlementQueryMx(this.queryParams).then((res) => {
        this.loading = false;
        this.tableData.records = [];
        if (
          res.code == 200 &&
          res.data &&
          res.data.code == 200 &&
          res.data.data
        ) {
          if (
            res.data.data.resp_code == "00000000" &&
            res.data.data.trans_log_result_list
          ) {
            this.tableData.records = JSON.parse(res.data.data.trans_log_result_list);
         
            this.tableData.total = Number(res.data.data.result_count)
          } else {
          }
        }
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.timer = [];
      this.handleQuery();
    },
    resetQuery() {
      this.timer = [];
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        beginDate: "",
        endDate: "",
      };
      this.getList();
    },
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  .search-box {
    // width: 790px;
    // margin: 0 auto;
  }
}
::v-deep .el-date-editor {
  .el-input__inner {
    padding-left: 30px;
  }
}
</style>
